var netTool 
var apiPath = 'capi/V2/ERgoodsShelf/erGoodsShelves/'
function ERgoodsShelf(_netTool){
	let user_id = uni.getStorageSync('userInfo').id
	netTool = _netTool
	this.list = function(data, fn) {
		netTool.getAjaxUrlValueBackground(apiPath + 'list', {
			...data
		}, function(res) {
			typeof fn == 'function' && fn(res);
		})
	}
	this.update = function(data, fn) {
		netTool.getAjaxUrlValueBackground(apiPath + 'update', {
			...data,
		}, function(res) {
			typeof fn == 'function' && fn(res);
		})
	}
	this.del = function (data, fn){
		 netTool.getAjaxUrlValueBackground(apiPath + 'del',{
			 ...data
		 },res => {
			 typeof fn == 'function' && fn(res);
		 })
	}
	this.save = function(data, fn) {
		try{
			netTool.getAjaxUrlValueBackground(apiPath + 'list', {
				...data,
			}, function(res) {
				console.log(res)
				 
				if(res.records == 0){
					netTool.getAjaxUrlValueBackground(apiPath + 'save',{
						...data,
					},res=> {
						uni.$u.toast('添加成功')
						typeof fn == 'function' && fn(res);
					})
				}else{
					let err = {
						success:false,
						message:'已经存在！'
					}
					uni.$u.toast('已存在该条目')
					typeof fn == 'function' && fn(err);
				}
				
				
			})
		}catch(e){
			//TODO handle the exception
			uni.$u.toast('系统出现问题，请重新进入')
		}
		
	}
}
module.exports = ERgoodsShelf;